import Vue from 'vue'
import VueRouter from 'vue-router'

const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
};

Vue.use(VueRouter);

const routes = [
    {
        path: '/',
        redirect: '/courses'
    },
    {
        path: '/about',
        name: 'about',
        component: () => import('../views/About.vue')
    },
    {
        path: '/student',
        name: 'student',
        component: () => import('../views/Student.vue')
    },
    {
        path: '/category',
        name: 'category',
        component: () => import('../views/category.vue')
    },
    {
        path: '/courses/:level',
        name: 'courses',
        component: () => import('../views/Courses.vue')
    },
    {
        path: '/problem/list',
        name: 'problemList',
        component: () => import('../views/problem/ProblemList.vue')
    }
    ,
    {
        path: '/problem/:problemId',
        name: 'problem-detail',
        component: () => import('../views/problem/ProblemDetail.vue')
    },
    {
        path: '/submission/list',
        name: 'submissionList',
        component: () => import('../views/submission/MainSubmissionList.vue')
    },
    {
        path: '/submission/:runId',
        name: 'submission-detail',
        component: () => import('../views/submission/SubmissionDetail.vue')
    },
    {
        name: 'login',
        path: '/login',
        component: () => import('../views/login/Login.vue')
    },
    {
        name: 'problem-summary',
        path: '/problem/:problemId/summary',
        component: () => import('../views/problem/ProblemSummary.vue')
    }
    ,
    {
        name: 'register',
        path: '/register',
        component: () => import('../views/login/Register.vue')
    },
    {
        name: 'forget-password',
        path: '/forget-password',
        component: () => import('../views/login/ForgetPassword')
    },

    {
        name: "contest-list",
        path: '/contest/list',
        component: () => import('../views/contest/ContestList.vue')
    },
    {
        path: '/contests/:contestId',
        component: () => import('../views/contest/ContestDetail'),
        children: [
            {
                name: 'contest-dashboard',
                path: '',
                component: () => import('../views/contest/children/ContestDashboard')
            },
            {
                name: 'contest-announcement-list',
                path: 'announcements',
                component: () => import('../views/contest/children/ContestAnnouncements')
            },
            {
                name: 'contest-problem-list',
                path: 'problems',
                component: () => import('../views/contest/children/ContestProblems')
            },
        ]
    },
    {
        name: 'contest-problem-detail',
        path: '/contests/:contestId/problems/:problemId',
        component: () => import('../views/contest/ContestProblemView')
    },
    {
        name: 'contest-submission-list',
        path: '/contests/:contestId/submissions',
        component: () => import('../views/contest/ContestSubmissions')
    },
    {
        name: 'contest-ranking',
        path: '/contests/:contestId/rankings',
        component: () => import('../views/contest/ContestRankings')
    },
    {
        name: 'user-profile',
        path: '/user/profile',
        component: () => import('../views/profile')
    },
    {
        path: '/settings',
        component: () => import('../views/settings'),
        meta: {requiredAuth: true},
        children: [
            {
                name: 'profile-settings',
                path: 'profile-settings',
                component: () => import('../views/settings/children/profileSettings/ProfileSettings')
            },
            {
                name: 'account-settings',
                path: 'account-settings',
                component: () => import('../views/settings/children/accountSettings/AccountSettings')
            }
        ]
    },
    {
        path: '/admin/problems/create',
        name: 'create-problem',
        component: () => import('../views/admin/problem/ProblemView')
    },
    {
        path: '/admin/problems/:problemId/edit',
        name: 'edit-problem',
        component: () => import('../views/admin/problem/ProblemView')
    },
    {
        path: '/admin/contest/create',
        name: 'create-contest',
        component: () => import('../views/admin/contest/ContestView')
    },
    {
        path: '/admin/contestList/:contestId/edit',
        name: 'edit-contest',
        component: () => import('../views/admin/contest/ContestView')
    },
    {
        path: '/admin',
        component: () => import('@/views/admin/AdminHome'),
        children: [
            {
                path: 'rejudge',
                component: () => import('@/views/admin/rejudge/Rejudge')
            }
            ,
            {
                path: 'examineUser',
                component: () => import('@/views/admin/examine/ExamineUser')
            },
            {
                path: 'problemList',
                name: 'admin-problem-list',
                component: () => import('../views/admin/problem/ProblemList')
            },
            {
                path: 'contestList',
                name: 'admin-contest-list',
                component: () => import('../views/admin/contest/ContestList')
            },
            {
                path: 'chapter',
                name: 'admin-chapter',
                component: () => import('../views/admin/chapter/chapter')
            },
            {
                path: 'section',
                name: 'admin-section',
                component: () => import('../views/admin/section')
            },
            {
                path: 'course',
                name: 'admin-course',
                component: () => import('../views/admin/course/course')
            },
            {
                path: 'category',
                name: 'admin-category',
                component: () => import('../views/admin/category')
            },
            {
                path: 'teacher',
                name: 'admin-teacher',
                component: () => import('../views/admin/teacher/teacher')
            },
            {
                path: 'file',
                name: 'admin-file',
                component: () => import('../views/admin/file')
            }
            ,
            {
                path: 'resource',
                name: 'admin-resource',
                component: () => import('../views/admin/resource')
            }
            ,
            {
                path: 'role',
                name: 'admin-role',
                component: () => import('../views/admin/role')
            }
        ]
    },

];

const index = new VueRouter({
    routes,
    mode: "history"
});

export default index
